<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
use app\common\cachemodel\AppConfig;
use app\common\lib\Util;
use think\Db;
use \think\Queue;
use Aliyun\Core\Config;
use Aliyun\Core\Profile\DefaultProfile;
use Aliyun\Core\DefaultAcsClient;
use Aliyun\Api\Sms\Request\V20170525\SendSmsRequest;
use think\response\Json;

define('LAST_PLANET', 13);// 婚神星
define('FORT', 14);// 福点
define('VERT', 15);// 宿命点
define('SON', 16);// 南交点
define('ASC', 17);// 上升点
define('IC', 18);// 天底
define('DES', 19);// 下降点
define('MC', 20);// 天顶

if (!function_exists('is_countable'))
{
    /**
     * 判断数据能否进行count
     * @param $data
     * @return mixed
     */
    function is_countable($data)
    {
        if (is_array($data) || is_object($data))
        {
            return true;
        }
        return false;
    }
}

/**
 * 计算年龄
 * @param $birthday
 * @return false|int|mixed|string
 */
function birthday($birthday)
{
    $age = strtotime($birthday);
    if ($age === false)
    {
        return false;
    }
    [$y1, $m1, $d1] = explode("-", date("Y-m-d", $age));
    $now = time();
    [$y2, $m2, $d2] = explode("-", date("Y-m-d", $now));
    $age = $y2 - $y1;
    if ((int)($m2 . $d2) < (int)($m1 . $d1))
        --$age;
    return $age;
}

/**
 * 星盘配置数据转为旧版数据格式
 * @param $setting
 * @return array
 */
function ChangeSettingFormat($setting)
{
    $planets_display = '';
    $planet_orb_all = [];
    foreach ($setting['planet'] as $k => $planet)
    {
        if ($planet[0])
        {
            $planets_display .= '1';
        } else
        {
            $planets_display .= '0';
        }
        if ($k < 10)
        {
            $planet_orb_all[] = $planet[1];
        }
    }
    $asps_display = [];
    $asp_orb_all = null;
    foreach ($setting['phase'] as $k => $phase)
    {
        if ($phase[0])
        {
            $asps_display[] = $k;
        }

        $asp_orb_all[$k] = $phase[1];
    }
    $arr = [
        'asp_orb_all' => $asp_orb_all,
        'asps_display' => $asps_display,
        'h_sys' => $setting['h_sys'],
        'planet_orb_all' => $planet_orb_all,
        'planets_display' => $planets_display,
        'is_default' => $setting['is_default']
    ];
    return $arr;
}

/**
 * 发起HTTPS请求
 * @param $url
 * @param $data
 * @param $header
 * @param string $type
 * @param int $post
 * @return bool|string|Json
 */
function curl_post($url, $data, $header, $type = 'json', $post = 1)
{
    $ch = curl_init();
    $res = curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_POST, $post);
    if ($post) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    $result = curl_exec($ch);
    //连接失败
    if ($result == false)
    {
        if ($type == 'json')
        {
            $result = json(['code' => 10052, 'msg' => 'Network error.']);
        } else
        {
            $result = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Response><code>10052</code><msg>网络错误</msg></Response>";
        }
    }
    curl_close($ch);
    return $result;
}

/**
 * 应用公共文件
 * @param int $len
 * @return string
 */
function round_str($len = 128)
{
    // 密码字符集，可任意添加你需要的字符
    $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';

    $password = '';
    for ($i = 0; $i < $len; $i++)
    {
        // 这里提供两种字符获取方式
        // 第一种是使用 substr 截取$chars中的任意一位字符；
        // 第二种是取字符数组 $chars 的任意元素
        // $password .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
        $password .= $chars[mt_rand(0, strlen($chars) - 1)];
    }
    return $password;
}

/**
 * 是否为夏令时时间
 * @param $hour
 * @param $minute
 * @param $second
 * @param $month
 * @param $day
 * @param $year
 * @return boolean [description]
 */
function isSummerTime($hour, $minute, $second, $month, $day, $year)
{
    // 夏令时时间  6个区间
    // 1.      1986年5月4日（凌晨2点）至9月14日（凌晨2点）；
    // 2.      1987年4月12日（凌晨2点）至9月13日（凌晨2点）；
    // 3.      1988年4月10日（凌晨2点）至9月11日（凌晨2点），
    // 4.      1989年4月16日（凌晨2点）至9月17日（凌晨2点），
    // 5.      1990年4月15日（凌晨2点）至9月16日（凌晨2点），
    // 6.      1991年4月14日（凌晨2点）至9月15日（凌晨2点）。
    $start_time = [
        mktime(2, 0, 0, 5, 4, 1986),
        mktime(2, 0, 0, 4, 12, 1987),
        mktime(2, 0, 0, 4, 10, 1988),
        mktime(2, 0, 0, 4, 16, 1989),
        mktime(2, 0, 0, 4, 15, 1990),
        mktime(2, 0, 0, 4, 14, 1991),
    ];
    $end_time = [
        mktime(2, 0, 0, 9, 14, 1986),
        mktime(2, 0, 0, 9, 13, 1987),
        mktime(2, 0, 0, 9, 11, 1988),
        mktime(2, 0, 0, 9, 17, 1989),
        mktime(2, 0, 0, 9, 16, 1990),
        mktime(2, 0, 0, 9, 15, 1991),
    ];

    $time = mktime($hour, $minute, $second, $month, $day, $year);

    for ($i = 0; $i < 6; $i++)
    {
        if ($time >= $start_time[$i] && $time < $end_time[$i]) return true;
    }

    return false;
}

/**
 * 对二维数组重新排序
 * @param array $array
 * @param string $sort_key
 * @param string $sort
 * @return array
 */
function resort(array $array, string $sort_key, string $sort = 'DESC')
{
    if (!empty($array))
    {
        $sort = strtoupper($sort);

        foreach ($array as $k1 => $d1)
        {
            foreach ($array as $k2 => $d2)
            {
                if ($k1 < $k2)
                {
                    if ($sort === 'DESC' && $array[$k1][$sort_key] < $array[$k2][$sort_key])
                    {
                        $temp = $array[$k1];
                        $array[$k1] = $array[$k2];
                        $array[$k2] = $temp;
                    } elseif ($sort === 'ASC' && $array[$k1][$sort_key] > $array[$k2][$sort_key])
                    {
                        $temp = $array[$k1];
                        $array[$k1] = $array[$k2];
                        $array[$k2] = $temp;
                    }
                }

            }
        }
    }
    return $array;
}

/**
 * 对三维数组重新排序
 * @param array $array
 * @param string $sort_key name1.name2
 * @param string $sort
 * @return array
 */
function resort3(array $array, string $sort_key, string $sort = 'DESC')
{
    if (!empty($array))
    {
        $sort = strtoupper($sort);
        $sortKeyArr = explode('.', $sort_key);
        if (count($sortKeyArr) > 1)
        {
            $sortKey1 = $sortKeyArr[0];
            $sortKey2 = $sortKeyArr[1];
            foreach ($array as $k1 => $d1)
            {
                foreach ($array as $k2 => $d2)
                {
                    if ($k1 < $k2)
                    {
                        if ($sort === 'DESC' && $array[$k1][$sortKey1][$sortKey2] < $array[$k2][$sortKey1][$sortKey2])
                        {
                            $temp = $array[$k1];
                            $array[$k1] = $array[$k2];
                            $array[$k2] = $temp;
                        } elseif ($sort === 'ASC' && $array[$k1][$sortKey1][$sortKey2] > $array[$k2][$sortKey1][$sortKey2])
                        {
                            $temp = $array[$k1];
                            $array[$k1] = $array[$k2];
                            $array[$k2] = $temp;
                        }
                    }
                }
            }
        } else
        {
            foreach ($array as $k1 => $d1)
            {
                foreach ($array as $k2 => $d2)
                {
                    if ($k1 < $k2)
                    {
                        if ($sort === 'DESC' && $array[$k1][$sort_key] < $array[$k2][$sort_key])
                        {
                            $temp = $array[$k1];
                            $array[$k1] = $array[$k2];
                            $array[$k2] = $temp;
                        } elseif ($sort === 'ASC' && $array[$k1][$sort_key] > $array[$k2][$sort_key])
                        {
                            $temp = $array[$k1];
                            $array[$k1] = $array[$k2];
                            $array[$k2] = $temp;
                        }
                    }
                }
            }
        }
    }
    return $array;
}

/**
 * 检测成相
 * @param array $planet1 成相星体组1
 * @param array $planet2 成相星体组2
 * @param array $phase_e 成相度数组 为空时检测是否成相
 * @param array $planets 需要检测的行星数据
 * @param integer $orb_limit 限制容许度
 * @return bool 是否满足成相条件
 */
function checkPhase(array $planet1 = [], array $planet2 = [], array $phase_e = [], array $planets = [], $orb_limit = -10)
{
    $result = false;
    // 若星体组为空  或  行星数据为空时 直接返回false
    if (empty($planet1) || empty($planet2) || empty($planets))
    {
        return $result;
    }
    // 遍历星体组1
    foreach ($planet1 as $p1)
    {
        // 遍历星体组2
        foreach ($planet2 as $p2)
        {
            // 成相
            if (isset($planets[$p1]['phase'][$p1 . '-' . $p2]))
            {
                // 若只检测是否成相
                if (empty($phase_e))
                {
                    // 限制容许度 并满足该条件
                    if ($orb_limit >= 0 && $planets[$p1]['phase'][$p1 . '-' . $p2]['phase_orb'] <= $orb_limit)
                    {
                        $result = true;
                    } // 限制容许度 不满足条件
                    elseif ($orb_limit >= 0 && $planets[$p1]['phase'][$p1 . '-' . $p2]['phase_orb'] > $orb_limit)
                    {
                        $result = false;
                    } //  不限容许度
                    elseif ($orb_limit < 0)
                    {
                        $result = true;
                    }
                } // 检测是否为具体相位
                elseif (in_array($planets[$p1]['phase'][$p1 . '-' . $p2]['phase_e'], $phase_e))
                {
                    // 限制容许度 并满足该条件
                    if ($orb_limit >= 0 && $planets[$p1]['phase'][$p1 . '-' . $p2]['phase_e'] <= $orb_limit)
                    {
                        $result = true;
                    } // 限制容许度 不满足条件
                    elseif ($orb_limit >= 0 && $planets[$p1]['phase'][$p1 . '-' . $p2]['phase_e'] > $orb_limit)
                    {
                        $result = false;
                    } //  不限容许度
                    elseif ($orb_limit < 0)
                    {
                        $result = true;
                    }
                }
            }
        }
    }
    return $result;
}

/**
 * 检测落座落宫
 * @param array $planet 星体
 * @param array $data 落宫组或落座组
 * @param array $planets 星体数据
 * @param string $type 具体检测落宫 或 检测落座
 * @param string $limit 之一 || 均
 * @return bool 是否成立
 */
function checkSignHouse(array $planet = [], array $data = [], array $planets = [], string $type = 'house', string $limit = 'one')
{
    $result = false;

    if (empty($planet) || empty($data) || empty($planets))
    {
        return $result;
    }
    $not_limit = true;

    foreach ($planet as $p)
    {
        if (!$result && $not_limit && isset($planets[$p]))
        {
            if ($limit == 'one'
                &&
                (
                    ($type === 'house' && in_array($planets[$p]['in_house_id'], $data))
                    || ($type === 'sign' && in_array($planets[$p]['in_sign_id'], $data))
                )
            )
            {
                $result = true;
            } elseif ($limit != 'one'
                &&
                (
                    ($type === 'house' && !in_array($planets[$p]['in_house_id'], $data))
                    || ($type === 'sign' && !in_array($planets[$p]['in_sign_id'], $data))
                )
            )
            {
                $not_limit = false;
            }
        }
    }

    if (($limit === 'one' && $result === true) || $limit != 'one' && $not_limit === true) return true;

    return false;
}

/**
 * 检测是否为四象星座
 * @param array $planet 星体组
 * @param array $data 四象星座id组  [1,2,3,0] 表示火土风水
 * @param array $planets 星体数据
 * @param string $limit 之一 || 均
 * @return bool 是否成立
 */
function checkQuadrature(array $planet = [], array $data = [], array $planets = [], string $limit = 'one')
{
    $result = false;

    if (empty($planet) || empty($data) || empty($planets))
    {
        return $result;
    }

    $not_limit = true;

    foreach ($planet as $p)
    {
        if (in_array($planets[$p]['in_sign_id'] % 4, $data))
        {
            $result = true;
        } else
        {
            $not_limit = false;
        }
    }
    if ($limit === 'one')
    {
        return $result;
    } else
    {
        return $not_limit;
    }
}

/**
 * 行星落座
 * @param int $longitude
 * @return int 1-12
 */
function InWhichSign($longitude = 0)
{
    $sign = (int)ceil($longitude / 29.999999999999);
    if ($sign < 1) $sign = 1;
    elseif ($sign > 12) $sign = 12;
    return $sign;
}

/**
 * 行星落宫
 * @param int $longitude
 * @param array $house
 * @return int 1-12
 */
function InWhichHouse($longitude = 0, $house = [])
{
    $house[13] = $house[1];
    $in_house = 12;
    for ($j = 1; $j <= 12; $j++)
    {
        $pl = $longitude + (1 / 36000);
        $h_now = $house[$j];
        $h_next = $house[$j + 1];

        if ($j < 12 && $h_now > $h_next)
            if (($pl >= $h_now && $pl < 360) || ($pl < $h_next && $pl >= 0)) $in_house = $j;
        if ($j == 12 && ($h_now > $house[1]))
            if (($pl >= $h_now && $pl < 360) || ($pl < $house[1] && $pl >= 0)) $in_house = $j;
        if (($pl >= $h_now) && ($pl < $h_next && ($j < 12))) $in_house = $j;
        if (($pl >= $h_now) && ($pl < $house[1]) && ($j == 12)) $in_house = $j;
    }
    return $in_house;
}

function Crunch($x)
{
    if ($x >= 0)
    {
        $y = $x - floor($x / 360) * 360;
    } else
    {
        $y = 360 + ($x - ((1 + floor($x / 360)) * 360));
    }

    return $y;
}

function mod360($x)
{
    return $x - (floor($x / 360) * 360);
}

function Get_OB_Ecl($jd)
{
    // fetch mean obliquity
    $t = ($jd - 2451545) / 36525;

    $epsilon = 23.43929111;
    $epsilon = $epsilon - (46.815 * $t / 3600);
    $epsilon = $epsilon - (0.00059 * $t * $t / 3600);
    $epsilon = $epsilon + (0.001813 * $t * $t * $t / 3600);
    return $epsilon;
}

/**
 * 私钥加密
 * @param $data
 * @return string|null
 */
function privEncrypt($data)
{
    if (!is_string($data)) return null;
    $private_key = openssl_pkey_get_private(config('app.private_key'));
    return openssl_private_encrypt($data, $encrypted, $private_key) ? base64_encode($encrypted) : null;
}

/**
 * 私钥解密
 * @param $encrypted
 * @return null
 */
function privDecrypt($encrypted)
{
    if (!is_string($encrypted)) return null;
    $private_key = openssl_pkey_get_private(config('app.private_key'));
    return (openssl_private_decrypt(base64_decode($encrypted), $decrypted, $private_key)) ? $decrypted : null;
}

/**
 * 生成float随机数
 * @param int $min 最小值
 * @param int $max 最大值
 * @return int
 */
function randomFloat($min = 0, $max = 1)
{
    return $min + mt_rand() / mt_getrandmax() * ($max - $min);
}

/**
 * 获取基础时间
 * @param null $time
 * @param int $timezone
 * @return false|int
 */
function get_base_time($time = null, $timezone = 8)
{
    // 夏令时时间  6个区间
    $start_time = [
        mktime(2, 0, 0, 5, 4, 1986),// 1. 1986年5月4日（凌晨2点）至9月14日（凌晨2点）；
        mktime(2, 0, 0, 4, 12, 1987),// 2.1987年4月12日（凌晨2点）至9月13日（凌晨2点）；
        mktime(2, 0, 0, 4, 10, 1988),// 3.1988年4月10日（凌晨2点）至9月11日（凌晨2点），
        mktime(2, 0, 0, 4, 16, 1989),// 4.1989年4月16日（凌晨2点）至9月17日（凌晨2点），
        mktime(2, 0, 0, 4, 15, 1990),// 5.1990年4月15日（凌晨2点）至9月16日（凌晨2点），
        mktime(2, 0, 0, 4, 14, 1991),// 6.1991年4月14日（凌晨2点）至9月15日（凌晨2点）。
    ];
    $end_time = [
        mktime(2, 0, 0, 9, 14, 1986),
        mktime(2, 0, 0, 9, 13, 1987),
        mktime(2, 0, 0, 9, 11, 1988),
        mktime(2, 0, 0, 9, 17, 1989),
        mktime(2, 0, 0, 9, 16, 1990),
        mktime(2, 0, 0, 9, 15, 1991),
    ];

    for ($i = 0; $i < 6; $i++)
    {
        if ($time > $start_time[$i] && $time < $end_time[$i])
        {
            $time -= 3600;// 夏令时，减一小时
            break;
        }
    }
    // 转换成格林尼治时间
    $time -= $timezone * 3600;

    return (int)($time);
}

/**
 * 入星座度数
 * 如：18°2'26''  || 18°3′
 * @param $deg
 * @param bool $get_sec
 * @return string [type] [description]
 */
function in_sign_deg($deg, $get_sec = false)
{
    $longitude = $deg;
    $sign_id = floor($longitude / 30);
    $pos_in_sign = $longitude - ($sign_id * 30);
    $deg = floor($pos_in_sign);
    $full_min = ($pos_in_sign - $deg) * 60;
    $min = floor($full_min);
    $sec = round(($full_min - $min) * 60);
    if ($deg < 10) $deg = '    ' . $deg;
    if ($min < 10) $min = '0' . $min;
    if ($sec < 10) $sec = '0' . $sec;
    if (!$get_sec)
    {
        // 四舍五入
        if ($sec >= 30) $min++;
        if ($min == 60)
        {
            $min = 0;
            $deg++;
        }
        return $deg . '°' . $min . "′";
    }
    return $deg . '°' . $min . "′" . $sec . '″';
}

/**
 * 获取用户星盘配置信息
 * @param null $uid 用户id
 * @param string $chart 当前看的是哪个星盘  如：天象盘、本命盘
 * @param int $tid
 * @return array
 * @throws \think\db\exception\DataNotFoundException
 * @throws \think\db\exception\ModelNotFoundException
 * @throws \think\exception\DbException
 */
function get_astro_setting($uid = null, $chart = 'now', $tid = 1)
{
    $setting = Db::table('app_astro_setting_' . $chart)->field('tid,asp_orb_all,asps_display,planets_display,planet_orb_all,h_sys')
        ->where(['uid' => $uid, 'tid' => $tid, 'status' => 0])
        ->cache('astro_set_' . $uid . '_' . $tid)
        ->find();

    if (!$setting || empty($setting))
    {
        // 去老库里面查询
        $setting = Db::table('app_astro_setting')
            ->field("$chart")
            ->where("uid=$uid and tid=$tid")->order('use_time DESC')->find();
        if (empty($setting) || $setting[$chart] === null)
        {
            $setting1 = [
                'now' => [
                    'asp_orb_all' => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'natal' => [
                    'asp_orb_all' => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100100001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'transits' => [
                    'asp_orb_all' => [0 => 2, 60 => 1, 90 => 2, 120 => 2, 180 => 2, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                    'style' => 'cn',
                    'firdaria' => 'default',
                ],
                'thirdprogressed' => [
                    //            'asp_orb_all'=> [0=>3,60=>2,90=>3,120=>3,180=>3,30=>1,150=>2,45=>2,135=>2,72=>2,144=>2],
                    'asp_orb_all' => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'thirdprogressedvsnatal' => [
                    'asp_orb_all' => [0 => 2, 60 => 1, 90 => 2, 120 => 2, 180 => 2, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                    'style' => 'cn',
                    'firdaria' => 'default',
                ],
                'progressions' => [
                    //            'asp_orb_all'=> [0=>2,60=>2,90=>2,120=>2,180=>2,30=>1,150=>2,45=>2,135=>2,72=>2,144=>2],
                    'asp_orb_all' => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'progressionsvsnatal' => [
                    'asp_orb_all' => [0 => 2, 60 => 1, 90 => 2, 120 => 2, 180 => 2, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                    'style' => 'cn',
                    'firdaria' => 'default',
                ],
                'solar' => [
                    'asp_orb_all' => [0 => 1, 60 => 0, 90 => 1, 120 => 0, 180 => 1, 30 => 0, 150 => 1, 45 => 1, 135 => 1, 72 => 0, 144 => 0],
                    'asps_display' => [0, 45, 90, 135, 180],
                    'planets_display' => '111111111100100001111',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'solar_return' => [
                    //            'asp_orb_all'=> [0=>8,60=>6,90=>7,120=>7,180=>7,30=>1,150=>2,45=>2,135=>2,72=>2,144=>2],
                    'asp_orb_all' => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100100001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'lunar_return' => [
                    //            'asp_orb_all'=> [0=>4,60=>2,90=>3,120=>3,180=>3.5,30=>0.5,150=>1,45=>1,135=>1,72=>0.5,144=>0.5],
                    'asp_orb_all' => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100100001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'firdaria' => [
                    'asp_orb_all' => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100100001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                    'firdaria' => 'default',
                ],
                'profection' => [
                    'asp_orb_all' => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100100001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'synastry' => [
                    'asp_orb_all' => [0 => 6, 60 => 4, 90 => 6, 120 => 6, 180 => 6, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100100001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'composite' => [
                    //            'asp_orb_all'=> [0=>4,60=>3,90=>4,120=>4,180=>4,30=>1,150=>2,45=>2,135=>2,72=>2,144=>2],
                    'asp_orb_all' => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'composite_thirdprogressed' => [
                    //            'asp_orb_all'=> [0=>5,60=>4,90=>5,120=>5,180=>5,30=>1,150=>2,45=>2,135=>2,72=>2,144=>2],
                    'asp_orb_all' => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'composite_progressions' => [
                    //            'asp_orb_all'=> [0=>4,60=>3,90=>4,120=>4,180=>4,30=>1,150=>2,45=>2,135=>2,72=>2,144=>2],
                    'asp_orb_all' => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                    'style' => 'cn',
                ],
                'davison' => [
                    //            'asp_orb_all'=> [0=>6,60=>5,90=>6,120=>6,180=>6,30=>1,150=>2,45=>2,135=>2,72=>2,144=>2],
                    'asp_orb_all' => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'marks' => [
                    //            'asp_orb_all'=> [0=>6,60=>5,90=>6,120=>6,180=>6,30=>1,150=>2,45=>2,135=>2,72=>2,144=>2],
                    'asp_orb_all' => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'divination' => [
                    'asp_orb_all' => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
            ];
            $setting2 = [
                'now' => [
                    'asp_orb_all' => [0 => 4, 60 => 2, 90 => 3, 120 => 3, 180 => 3.5, 30 => 0.5, 150 => 1, 45 => 1, 135 => 1, 72 => 0.5, 144 => 0.5],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [3, 2.5, 1, 1, 1, 1.5, 1.5, 1, 1, 0.5],
                    'h_sys' => 'p',
                ],
                'natal' => [
                    'asp_orb_all' => [0 => 4, 60 => 2, 90 => 3, 120 => 3, 180 => 3.5, 30 => 0.5, 150 => 1, 45 => 1, 135 => 1, 72 => 0.5, 144 => 0.5],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [3, 2.5, 1, 1, 1, 1.5, 1.5, 1, 1, 0.5],
                    'h_sys' => 'p',
                ],
                'transits' => [
                    'asp_orb_all' => [0 => 2, 60 => 1, 90 => 2, 120 => 2, 180 => 2, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'thirdprogressed' => [
                    'asp_orb_all' => [0 => 3, 60 => 2, 90 => 3, 120 => 3, 180 => 3, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'thirdprogressedvsnatal' => [
                    'asp_orb_all' => [0 => 2, 60 => 1, 90 => 2, 120 => 2, 180 => 2, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'progressions' => [
                    'asp_orb_all' => [0 => 2, 60 => 2, 90 => 2, 120 => 2, 180 => 2, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'progressionsvsnatal' => [
                    'asp_orb_all' => [0 => 2, 60 => 1, 90 => 2, 120 => 2, 180 => 2, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'solar' => [
                    'asp_orb_all' => [0 => 1, 60 => 0, 90 => 1, 120 => 0, 180 => 1, 30 => 0, 150 => 1, 45 => 1, 135 => 1, 72 => 0, 144 => 0],
                    'asps_display' => [0, 45, 90, 135, 180],
                    'planets_display' => '111111111100100001111',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'solar_return' => [
                    'asp_orb_all' => [0 => 4, 60 => 2, 90 => 3, 120 => 3, 180 => 3.5, 30 => 0.5, 150 => 1, 45 => 1, 135 => 1, 72 => 0.5, 144 => 0.5],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [3, 2.5, 1, 1, 1, 1.5, 1.5, 1, 1, 0.5],
                    'h_sys' => 'p',
                ],
                'lunar_return' => [
                    'asp_orb_all' => [0 => 4, 60 => 2, 90 => 3, 120 => 3, 180 => 3.5, 30 => 0.5, 150 => 1, 45 => 1, 135 => 1, 72 => 0.5, 144 => 0.5],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100100001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'firdaria' => [
                    'asp_orb_all' => [0 => 4, 60 => 2, 90 => 3, 120 => 3, 180 => 3.5, 30 => 0.5, 150 => 1, 45 => 1, 135 => 1, 72 => 0.5, 144 => 0.5],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [3, 2.5, 1, 1, 1, 1.5, 1.5, 1, 1, 0.5],
                    'h_sys' => 'p',
                    'firdaria' => 'default',
                ],
                'profection' => [
                    'asp_orb_all' => [0 => 4, 60 => 2, 90 => 3, 120 => 3, 180 => 3.5, 30 => 0.5, 150 => 1, 45 => 1, 135 => 1, 72 => 0.5, 144 => 0.5],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [3, 2.5, 1, 1, 1, 1.5, 1.5, 1, 1, 0.5],
                    'h_sys' => 'p',
                ],
                'synastry' => [
                    'asp_orb_all' => [0 => 6, 60 => 4, 90 => 6, 120 => 6, 180 => 6, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100100001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'composite' => [
                    'asp_orb_all' => [0 => 4, 60 => 3, 90 => 4, 120 => 4, 180 => 4, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'composite_thirdprogressed' => [
                    'asp_orb_all' => [0 => 5, 60 => 4, 90 => 5, 120 => 5, 180 => 5, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'composite_progressions' => [
                    'asp_orb_all' => [0 => 4, 60 => 3, 90 => 4, 120 => 4, 180 => 4, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'davison' => [
                    'asp_orb_all' => [0 => 6, 60 => 5, 90 => 6, 120 => 6, 180 => 6, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'marks' => [
                    'asp_orb_all' => [0 => 6, 60 => 5, 90 => 6, 120 => 6, 180 => 6, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'divination' => [
                    'asp_orb_all' => [0 => 4, 60 => 2, 90 => 3, 120 => 3, 180 => 3.5, 30 => 0.5, 150 => 1, 45 => 1, 135 => 1, 72 => 0.5, 144 => 0.5],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all' => [3, 2.5, 1, 1, 1, 1.5, 1.5, 1, 1, 0.5],
                    'h_sys' => 'p',
                ],
            ];
            $setting3 = [
                'now' => [
                    'asp_orb_all' => [0 => 7, 60 => 5, 90 => 6, 120 => 6, 180 => 6, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180, 30, 150],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'natal' => [
                    'asp_orb_all' => [0 => 7, 60 => 5, 90 => 6, 120 => 6, 180 => 6, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180, 30, 150],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'transits' => [
                    'asp_orb_all' => [0 => 2, 60 => 1, 90 => 2, 120 => 2, 180 => 2, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'thirdprogressed' => [
                    'asp_orb_all' => [0 => 3, 60 => 2, 90 => 3, 120 => 3, 180 => 3, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'thirdprogressedvsnatal' => [
                    'asp_orb_all' => [0 => 3, 60 => 2, 90 => 3, 120 => 3, 180 => 3, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'progressions' => [
                    'asp_orb_all' => [0 => 2, 60 => 2, 90 => 2, 120 => 2, 180 => 2, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'progressionsvsnatal' => [
                    'asp_orb_all' => [0 => 2, 60 => 2, 90 => 2, 120 => 2, 180 => 2, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'solar' => [
                    'asp_orb_all' => [0 => 1, 60 => 0, 90 => 1, 120 => 0, 180 => 1, 30 => 0, 150 => 1, 45 => 1, 135 => 1, 72 => 0, 144 => 0],
                    'asps_display' => [0, 45, 90, 135, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'solar_return' => [
                    'asp_orb_all' => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'lunar_return' => [
                    'asp_orb_all' => [0 => 4, 60 => 2, 90 => 3, 120 => 3, 180 => 3.5, 30 => 0.5, 150 => 1, 45 => 1, 135 => 1, 72 => 0.5, 144 => 0.5],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'firdaria' => [
                    'asp_orb_all' => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                    'style' => 'cn',
                    'firdaria' => 'default',
                ],
                'profection' => [
                    'asp_orb_all' => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'synastry' => [
                    'asp_orb_all' => [0 => 6, 60 => 4, 90 => 6, 120 => 6, 180 => 6, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'composite' => [
                    'asp_orb_all' => [0 => 4, 60 => 3, 90 => 4, 120 => 4, 180 => 4, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'composite_thirdprogressed' => [
                    'asp_orb_all' => [0 => 5, 60 => 4, 90 => 5, 120 => 5, 180 => 5, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'composite_progressions' => [
                    'asp_orb_all' => [0 => 4, 60 => 3, 90 => 4, 120 => 4, 180 => 4, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'davison' => [
                    'asp_orb_all' => [0 => 6, 60 => 5, 90 => 6, 120 => 6, 180 => 6, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'marks' => [
                    'asp_orb_all' => [0 => 6, 60 => 5, 90 => 6, 120 => 6, 180 => 6, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
                'divination' => [
                    'asp_orb_all' => [0 => 7, 60 => 5, 90 => 6, 120 => 6, 180 => 6, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display' => [0, 60, 90, 120, 180, 30, 150],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys' => 'p',
                ],
            ];

            if ($tid == 1) $setting = ($setting1[$chart]);
            elseif ($tid == 2) $setting = ($setting2[$chart]);
            elseif ($tid == 3) $setting = ($setting3[$chart]);
//            dump($setting);
            $setting['tid'] = $tid;

        } // 若原来有设置，则自动添加到新的数据表中
        elseif (!empty($setting) && $setting[$chart] != null)
        {
            $divination = json_decode($setting[$chart], true);
            $db_data['tid'] = $tid;
            $db_data['uid'] = $uid;
            $db_data['asp_orb_all'] = json_encode($divination['asp_orb_all']);
            $db_data['asps_display'] = json_encode($divination['asps_display']);
            $db_data['planet_orb_all'] = json_encode($divination['planet_orb_all']);
            $db_data['planets_display'] = $divination['planets_display'];
            $db_data['create_time'] = time();
//            Db::table('app_astro_setting_'.$chart)->insertGetId($db_data); // 存入新版数据表
            $divination['tid'] = $tid;
            $setting = $divination;
        }
    } else
    {
        $setting['asp_orb_all'] = json_decode($setting['asp_orb_all'], true);
        $setting['asps_display'] = json_decode($setting['asps_display'], true);
        $setting['planet_orb_all'] = json_decode($setting['planet_orb_all'], true);
    }
//    dump('uid:===='.$uid.'====tid:'.$tid);
//    dump($setting);
//    exit;
    return $setting;
}

/**
 * 相位出入相
 * @param $asp int 相位度数
 * @param $deg1 float 行星度数1
 * @param $deg2 float 行星度数2
 * @param $speed1  float 速度1
 * @param $speed2 float 速度2
 * @param $vs 1=>行星1为本命 2=> 行星2为本命     本命盘速度为0
 * @return bool true 为入相  false 为出相
 */
function phase_in_or_out($asp, $deg1, $deg2, $speed1, $speed2, $vs = 0)
{
    $da = abs($deg1 - $deg2);

    if ($da > 180) $da = 360 - $da;
    // VS 本命盘计算出入相位
    if ($vs)
    {
        if ($vs == 1)
        {
            $fixed = $deg1;
            $speed1 = 0;
        } elseif ($vs == 2)
        {
            $fixed = $deg2;
            $speed2 = 0;
        }
        $accurate_deg1 = $fixed + $asp;
        $accurate_deg2 = $fixed - $asp;

    }
    if (abs($speed1) > abs($speed2))
    {
        $s3 = $speed1 - $speed2;
        $da3 = abs($deg1 - $deg2 + $s3);
    } else
    {
        $s3 = $speed2 - $speed1;
        $da3 = abs($deg1 - $deg2 - $s3);
    }
    if ($da3 > 180) $da3 = 360 - $da3;
    if (abs($da - $asp) > abs($da3 - $asp)) return true;
    return false;

}

/**
 * 发送短信接口
 * 文档地址 https://help.aliyun.com/document_detail/55491.html?spm=5176.doc55491.6.560.0KUKny
 * @param $mobile int   手机号
 * @param $params array   模板替换参数
 * @param $code string 短信模版
 * @return mixed    code = OK 表示完成
 */
function sendSms($mobile, $params, $code)
{
    require_once VENDOR_PATH . '/aliyunsms/vendor/autoload.php';

    $alidayu = (new AppConfig())->configInfo('alidayu');
    //获取短信配置
    $appkey = $alidayu['appkey'];
    $secretkey = $alidayu['secretkey'];
    $name = $alidayu['name'];

    Config::load();
    $templateParam = $params;
    $product = "Dysmsapi";
    $domain = "dysmsapi.aliyuncs.com";
    $region = "cn-hangzhou";

    $profile = DefaultProfile::getProfile($region, $appkey, $secretkey);
    DefaultProfile::addEndpoint("cn-hangzhou", "cn-hangzhou", $product, $domain);
    $acsClient = new DefaultAcsClient($profile);
    $request = new SendSmsRequest();
    $request->setPhoneNumbers($mobile);
    $request->setSignName($name);
    $request->setTemplateCode($code);
    if ($templateParam) $request->setTemplateParam(json_encode($templateParam, JSON_UNESCAPED_UNICODE));

    $acsResponse = $acsClient->getAcsResponse($request);
    $result = json_decode(json_encode($acsResponse), true);
    return $result;
}

/**
 * 加入队列
 * @param $task
 * @param $jobData
 * @param $queue
 * @param int $delay
 */
function queuePush($task, $jobData, $queue, $delay = 0)
{
    $isUseRabbitmq = 0;//是否使用Rabbitmq，1：使用；0不使用；
    if ($isUseRabbitmq)
    {
        require_once __DIR__ . '/common/lib/RabbitmqRectificationProducer.php';

        RabbitmqRectificationProducer::sendMessage($delay, $jobData);
    }// 使用think-queue+redis的方式实现消息队列
    else
    {
        if ($delay <= 0)
        {
            try
            {
                Queue::push($task, $jobData, $queue);// 立即执行
            }
            catch (\Exception $e)
            {
                // 加入立即执行队列失败
                \think\Log::write('加入立即执行队列失败:' . var_export($jobData, true), 'error', true);
            }
        } else
        {
            try
            {
                Queue::later($delay, $task, $jobData, $queue);// 延迟15分钟执行
            }
            catch (\Exception $e)
            {
                // 加入立即延时队列失败
                \think\Log::write('加入立即延时队列失败:' . var_export($jobData, true), 'error', true);
            }
        }
    }

}

/**
 * 检查档案时间格式
 * @param $year
 * @param $month
 * @param $day
 * @param $hour
 * @param $minute
 * @param $timezone
 */
function checkRecodeData($year = null, $month = null, $day = null, $hour = null, $minute = null, $timezone = null)
{
    // 年份限制 1000 - 2999
    if ($year === null || $year < 1000 || $year > 2999)
    {
        echo json_encode(['code' => 0, 'msg' => 'Year Invalid.']);
        exit;
    }
    // 月份限制 1-12
    if ($month === null || $month < 0 || $month > 12)
    {
        echo json_encode(['code' => 0, 'msg' => 'Month Invalid.']);
        exit;
    }
    // 日期限制 1-31
    if ($day === null || $day < 0 || $day > 31
        || (is_bissextile($year) && $month == 2 && $day > 29)
        || (!is_bissextile($year) && $month == 2 && $day > 28)
        || (in_array($month, [4, 6, 9, 11]) && $day > 30))
    {
        echo json_encode(['code' => 0, 'msg' => 'Day Invalid.']);
        exit;
    }
    // 小时限制 0-23
    if ($hour === null || $hour < 0 || $hour > 23)
    {
        echo json_encode(['code' => 0, 'msg' => 'Hour Invalid.']);
        exit;
    }
    // 分钟限制 0-59
    if ($minute === null || $minute < 0 || $minute > 59)
    {
        echo json_encode(['code' => 0, 'msg' => 'Minute Invalid.']);
        exit;
    }
    if ($timezone < -12 || $timezone > 12)
    {
        echo json_encode(['code' => 0, 'msg' => 'Timezone Invalid.']);
        exit;
    }
}

/**
 * 判断是否为闰年
 * 闰年 true || 平年 false
 * @param null $year
 * @return bool
 */
function is_bissextile($year = null)
{
    if ($year === null)
    {
        echo json_encode(['code' => 10719, 'msg' => 'Year Invalid.']);
        exit;
    }
    if ($year % 400 === 0 || ($year % 100 !== 0 && $year % 4 === 0))
    {
        return true;
    }
    return false;
}

/**
 * 检测某星体度数是否在两个度数之间
 * @param $deg
 * @param $deg1
 * @param $deg2
 * @param $orb int 相差多少度为特殊情况（即$deg1 在白羊座0度附近）
 * @return bool
 */
function isBetweenIn($deg, $deg1, $deg2, $orb = 270)
{
    // $deg1 = 356  $deg2 = 2  =>  362
    if ($deg1 > $deg2 && $deg1 - $deg2 > $orb)
    {
        // $deg = 3   =>   363
        if ($deg1 - $deg > $orb && $deg > $deg2)
        {
            return true;
        } // $deg = 358
        elseif ($deg > $deg1)
        {
            return true;
        }
    } // $deg2 = 356  $deg1 = 2  =>  362
    elseif ($deg1 < $deg2 && $deg2 - $deg1 > $orb)
    {
        // $deg = 3   =>   363
        if ($deg2 - $deg > $orb && $deg > $deg1)
        {
            return true;
        } // $deg = 358
        elseif ($deg > $deg2)
        {
            return true;
        }
    } else
    {
        if (($deg > $deg2 && $deg < $deg1) || ($deg > $deg1 && $deg < $deg2))
        {
            return true;
        }
    }
    return false;
}

/**
 * 通用化API接口数据输出
 * @param int $code 业务状态码
 * @param string $msg 信息提示
 * @param array $data 数据
 * @param int $httpCode http状态码
 * @return Json
 */
function show($code, $msg, $data = [], $httpCode = 200)
{
    if (isset($data['lucky_toast']))
    {   // 完成幸运星任务 弹窗 获得幸运星信息
        $luckyToast = $data['lucky_toast'];
        unset($data['lucky_toast']);
    }

    $data = [
        'code' => $code,
        'msg' => $msg,
        'data' => empty($data) ? null : $data,
        'lucky_toast' => $luckyToast ?? null
    ];

    $GLOBALS['response_code'] = $code;
    return json($data, $httpCode);
}

/**
 * 获取档案星盘数据
 * @param null $year
 * @param null $month
 * @param null $day
 * @param null $hour
 * @param null $minute
 * @param null $longitude
 * @param null $latitude
 * @param int $timezone
 * @param string $h_sys
 * @return array
 */
function getTheRecodeAstro($year = null, $month = null, $day = null, $hour = null, $minute = null, $longitude = null, $latitude = null, $timezone = 8, $h_sys = 'p')
{
    $time = getTheBaseTime($year, $month, $day, $hour, $minute, $timezone);
    $utdatenow = strftime("%d.%m.%Y", $time);
    $utnow = strftime("%H:%M:%S", $time);

    exec(config('astrolog.prefix') . " -b{$utdatenow} -ut{$utnow} -p0123456789DAtHt -eswe -house{$longitude},{$latitude},{$h_sys} -flds -g, -head", $out);

    $data = getOriginalData($out);

    $result = [];
    $result['sun'] = InWhichSign($data['p1'][0]) . '-' . InWhichHouse($data['p1'][0], $data['hc1']) . '-' . $data['p1'][0];
    $result['moon'] = InWhichSign($data['p1'][1]) . '-' . InWhichHouse($data['p1'][1], $data['hc1']) . '-' . $data['p1'][1];
    $result['merc'] = InWhichSign($data['p1'][2]) . '-' . InWhichHouse($data['p1'][2], $data['hc1']) . '-' . $data['p1'][2];
    $result['venu'] = InWhichSign($data['p1'][3]) . '-' . InWhichHouse($data['p1'][3], $data['hc1']) . '-' . $data['p1'][3];
    $result['mars'] = InWhichSign($data['p1'][4]) . '-' . InWhichHouse($data['p1'][4], $data['hc1']) . '-' . $data['p1'][4];
    $result['jupi'] = InWhichSign($data['p1'][5]) . '-' . InWhichHouse($data['p1'][5], $data['hc1']) . '-' . $data['p1'][5];
    $result['satu'] = InWhichSign($data['p1'][6]) . '-' . InWhichHouse($data['p1'][6], $data['hc1']) . '-' . $data['p1'][6];
    $result['non'] = InWhichSign($data['p1'][12]) . '-' . InWhichHouse($data['p1'][12], $data['hc1']) . '-' . $data['p1'][12];
    $result['lili'] = InWhichSign($data['p1'][11]) . '-' . InWhichHouse($data['p1'][11], $data['hc1']) . '-' . $data['p1'][11];
    $result['juno'] = InWhichSign($data['p1'][13]) . '-' . InWhichHouse($data['p1'][13], $data['hc1']) . '-' . $data['p1'][13];
    $result['asc'] = InWhichSign($data['p1'][17]) . '-' . InWhichHouse($data['p1'][17], $data['hc1']) . '-' . $data['p1'][17];
    $result['mc'] = InWhichSign($data['p1'][20]) . '-' . InWhichHouse($data['p1'][20], $data['hc1']) . '-' . $data['p1'][20];

    return $result;
}

/**
 * 初始化本命盘
 * @param array $data
 * @param string $h_sys
 * @return array
 */
function getOriginalData($data = [], $h_sys = 'p')
{
    foreach ($data as $key => $line)
    {
        $row = explode(',', $line);
        $planet[$key] = $row[0] * 1;
        $speed[$key] = $row[1] * 1;
    };

    // 判断是日间盘还是夜间盘
    if ($planet[15] > $planet[21])
        if ($planet[0] <= $planet[15] and $planet[0] > $planet[21])
            $day_chart = true;
        else
            $day_chart = false;
    else
        if ($planet[0] > $planet[15] and $planet[0] <= $planet[21])
            $day_chart = false;
        else
            $day_chart = true;

    $juno = $planet[13];// 婚神星
    // 计算福点位置
    if ($day_chart == true) $fort = $planet[15] + $planet[1] - $planet[0];
    else $fort = $planet[15] - $planet[1] + $planet[0];
    if ($fort >= 360) $fort -= 360;
    if ($fort < 0) $fort += 360;

    // 计算宿命点度数
    $vert = $planet[30];

    $hc = [];
    // 此处 加入特殊分宫制   整宫制
    if ($h_sys == 'w')
    {
        $hc[1] = floor($planet[15] / 30) * 30;
        for ($i = 1; $i <= 14; $i++)
        {
            $house = $hc[1] + ($i - 1) * 30;
            if ($house > 360)
            {
                $house -= 360;
            }
            $hc[$i] = $house;
            unset($planet[14 + $i]);
        }
    } else
    {
        for ($i = 1; $i <= 14; $i++)
        {
            $hc[$i] = $planet[14 + $i];
            unset($planet[14 + $i]);
        }
    }
    unset($hc[13]);
    unset($hc[14]);
    unset($planet[29]);
    unset($planet[30]);

    $planet[13] = $juno;// 婚神星
    $planet[14] = $fort;// 福点
    $planet[15] = $vert;// 宿命点
    $planet[16] = $planet[12] > 180 ? $planet[12] - 180 : $planet[12] + 180;// 增加南交点
    // 加四轴 放入行星组中
    $planet[17] = $hc[1];// 上升点
    $planet[18] = $hc[4];// 天底
    $planet[19] = $hc[7];// 下降点
    $planet[20] = $hc[10];// 天顶

    $retro = getRetroData($speed);

    $returnData = ['rx1' => $retro, 'p1' => $planet, 'hc1' => $hc, 'speed' => $speed];

    return $returnData;
}

/**
 * 获取是否逆行数据
 * @param  [type] $speed [description]
 * @return [type]        [description]
 */
function getRetroData($speed)
{
    $retro = '';

    for ($i = 0; $i <= 13; $i++)
    {
        if (@$speed[$i] < 0) $retro .= "R";
        else $retro .= " ";
    }

    return $retro;
}

/**
 * 获取基础时间
 * @param null $year
 * @param null $month
 * @param null $day
 * @param null $hour
 * @param null $minute
 * @param int $timezone
 * @return false|int
 */
function getTheBaseTime($year = null, $month = null, $day = null, $hour = null, $minute = null, $timezone = 8)
{
    if (isSummerTime($hour, $minute, 0, $month, $day, $year))
    {
        $hour--;// 夏令时减一小时
    }

    if ($timezone >= 0)
    {
        $whole = floor($timezone);
        $fraction = $timezone - floor($timezone);
    } else
    {
        $whole = ceil($timezone);
        $fraction = $timezone - ceil($timezone);
    }
    $hour = $hour - $whole;
    $minute = $minute - ($fraction * 60);

    $time = mktime($hour, $minute, 0, $month, $day, $year);

    return $time;
}

/**
 * solar eclipse
 * lunar eclipse
 * @param int $time 天象时间
 * @param int $timezone 时区
 * @param int $type 类型 0日食 1月食
 * @return false|int
 */
function getEclipse(int $time = 0, int $timezone = 8, $type = 0)
{
    $start_time = [
        mktime(2, 0, 0, 5, 4, 1986),
        mktime(2, 0, 0, 4, 12, 1987),
        mktime(2, 0, 0, 4, 10, 1988),
        mktime(2, 0, 0, 4, 16, 1989),
        mktime(2, 0, 0, 4, 15, 1990),
        mktime(2, 0, 0, 4, 14, 1991),
    ];
    $end_time = [
        mktime(2, 0, 0, 9, 14, 1986),
        mktime(2, 0, 0, 9, 13, 1987),
        mktime(2, 0, 0, 9, 11, 1988),
        mktime(2, 0, 0, 9, 17, 1989),
        mktime(2, 0, 0, 9, 16, 1990),
        mktime(2, 0, 0, 9, 15, 1991),
    ];

    $change = 0;

    for ($i = 0; $i < 6; $i++) if ($time > $start_time[$i] && $time < $end_time[$i]) $change -= 3600;

    $change -= $timezone * 3600;

    $time += $change;

    $utdatenow = strftime("%d.%m.%Y", $time);

    if ($type == 1)
    {
        $exec_str = config('astrolog.prefix') . " -b{$utdatenow} -lunecl -eswe -g, -head";// 月食
    } else
    {
        $exec_str = config('astrolog.prefix') . " -b{$utdatenow} -solecl -eswe -g, -head";// 日食
    }
    exec($exec_str, $out);

    $arr = explode(',', $out[1]);

    $time_b = trim($arr[1]);
    $time_a = trim($arr[2]);
    $time_a = substr($time_a, 0, -2);
    $time_a_arr = explode(':', $time_a);
    $time_a = $time_a_arr[0] * 1 . '.' . $time_a_arr[1] * 1 . '.' . $time_a_arr[2] * 1;

    $timestamp = strtotime($time_b . ' ' . $time_a);

    $timestamp -= $change;

    return $timestamp;
}

/**
 * 检测是否构成T三角
 * @param array $t_square
 * @param int $pid
 * @return bool
 */
function is_in_t_square(array $t_square, int $pid)
{
    if (!empty($t_square))
    {
        foreach ($t_square as $t_s)
        {
            if (in_array($pid, $t_s))
            {
                return true;
            }
        }
    }
    return false;
}

/**
 * 获取当前月份天数
 * @param $time
 * @return array
 */
function month_days($time)
{
    //获取当前月份天数
    $j = date("t", $time);
    $start_time = strtotime(date('Y-m-01', $time));  //获取本月第一天时间戳
    $month = [];
    for ($i = $start_time; $i < strtotime('+1 month', $start_time);)
    {
        $month[] = $i; //每隔一天赋值给数组
        $i = strtotime('+1 day', $i);
    }
    return $month;
}

/**
 * 检测是否有订单超时未支付
 * 超时时间为一天：24小时
 * 进行关闭订单操作，
 * TODO 进行缓存更新操作
 * @param int $uid
 * @return Json
 */
function check_overtime($uid = 0)
{
    $where = ['status' => 0, 'uid' => $uid];
    try
    {
        // 获取当前用户的所有未支付订单
        $orders = Db::table('app_orders')
            ->field('id,create_time,pay_time')
            ->where($where)
            ->select();
        // 获取校准生辰未支付订单
        $recs = Db::table('app_rectification')
            ->alias('re')
            ->join('app_orders or', 're.id=or.reid', 'LEFT')
            ->where(['or.uid' => $uid])
            ->order('or.id', 'ASC')
            ->column('or.id,or.create_time,or.pay_time,or.order_id', 'or.reid');

        foreach ($orders as $k => $v)
        {
            $overtime = strtotime("+24hours", $v['create_time']);

            if (time() > $overtime && !$v['pay_time'])
            {
                Db::table('app_orders')->where('id', $v['id'])->update(['status' => 2]);
            }
        }


        foreach ($recs as $k => $v)
        {
            $overtime = strtotime("+24hours", $v['create_time']);

            if (time() > $overtime && !$v['pay_time'])
            {
                Db::table('app_rectification')->where('id', $k)->update(['status' => 5]);
            }
        }
    }
    catch (\Exception $e)
    {
        \think\Log::write('修改的订单关闭状态失败' . $e->getMessage() . var_export(request()->param(), true), 'close_order_error', true);
        return show(config('code.error'), '订单状态修改失败');
    }
}

/**
 * 关联数组去重复
 * @param $array
 * @param bool $recursion
 * @return array
 */
function super_unique($array, $recursion = false)
{
    // 序列化数组元素,去除重复
    $result = array_map('unserialize', array_unique(array_map('serialize', $array)));
    // 递归调用
    if ($recursion)
    {
        foreach ($result as $key => $value)
        {
            if (is_array($value))
            {
                $result[$key] = super_unique($value);
            }
        }
    }
    return $result;
}

/**
 * 获取分页数据
 * @param $total
 * @param int $page
 * @param int $listrows
 * @return array
 */
function getPaginatorData($total, $page = 1, $listrows = 10)
{
    $per_page = $listrows;// 当前栏目每页文章总数
    $current_page = $page;// 当前栏目文章起始页码
    $last_page = (int)ceil($total / $per_page);// 最后一页的页码

    $start = ($current_page - 1) * $per_page;// 开始id
    $end = $listrows;// 分页长度

    $pagination = [
        'start' => $start,
        'end' => $end,
        'total' => $total,
        'per_page' => $per_page,
        'current_page' => $current_page,
        'last_page' => $last_page,
        'data' => []
    ];

    return $pagination;
}

/**
 * 保证数值在 0～100之间
 * @param int $value
 * @return int
 */
function Mod100($value = 0)
{
    return $value > 100 ? 100 : ($value < 0 ? 0 : $value);
}

/**
 * 检测网络是否连接
 * @param $url
 * @return bool
 */
function varify_url($url)
{
    $check = @fopen($url, "r");
    if ($check)
    {
        $status = true;
    } else
    {
        $status = false;
    }
    return $status;
}

/**
 * 获取三限容许系数
 * @param int $orb 当前相位真实容许度
 * @return float|int
 */
function getThirdprogressedModulus($orb = 0)
{
    // 三次限容许系数
    // 1度内1
    if ($orb < 1)
    {
        $modulus = 1;
    } // 1-2度 0.95
    elseif ($orb < 2)
    {
        $modulus = 0.95;
    } // 2-3度 0.9
    elseif ($orb < 3)
    {
        $modulus = 0.9;
    } // 3-4度 0.85
    elseif ($orb <= 4)
    {
        $modulus = 0.85;
    } // 4-5度 0.8
    elseif ($orb <= 5)
    {
        $modulus = 0.8;
    } // 5度外 0.7
    else
    {
        $modulus = 0.7;
    }
    return $modulus;
}

/**
 * 获取行运容许系数
 * @param int $orb 当前相位真实容许度
 * @return float|int
 */
function getTransitsModulus($orb = 0)
{
    // 行运容许系数
    // 30分内 1
    if ($orb < 0.5)
    {
        $modulus = 1;
    } // 1度内 0.95
    elseif ($orb < 1)
    {
        $modulus = 0.95;
    } // 1.5内 0.85
    elseif ($orb < 1.5)
    {
        $modulus = 0.85;
    } // 2内 0.7
    else
    {
        $modulus = 0.7;
    }

    return $modulus;

}

/**
 * 获取一段时间范围内的具体所有时间 , 无前导零
 * @param array $map
 *  start string 开始时间
 *  end string 结束时间
 *  type int 1=>年-月-日  2=>年-月  3=>年
 * @return array
 */
function prDates($map = [])
{

    $start = $map['start'];
    $end = $map['end'];
    $type = $map['type'];

    $time = [];
    //判断时间类型  年/月/日
    switch ($type)
    {
        case 1:
            $dt_start = strtotime($start);
            $dt_end = strtotime($end);
            //日
            while ($dt_start <= $dt_end)
            {
                $time[] = date('Y-n-j', $dt_start);
                $dt_start = strtotime('+1 day', $dt_start);
            }
            break;
        case 2:
            $dt_start = strtotime($start);
            $dt_end = strtotime($end);
            //月
            while ($dt_start <= $dt_end)
            {
                $time[] = date('Y-n', $dt_start);
                $dt_start = strtotime('+1 month', $dt_start);
            }
            break;
        case 3:
            $dt_start = strtotime($start . '-1');
            $dt_end = strtotime($end . '-1');
            //年
            while ($dt_start <= $dt_end)
            {
                $time[] = date('Y', $dt_start);
                $dt_start = strtotime('+1 year', $dt_start);
            }
            break;
    }
    return $time;
}

/**
 * 获取一段时间范围内的具体所有时间 , 有前导零
 * @param array $map
 *  start string 开始时间
 *  end string 结束时间
 *  type int 1=>年-月-日  2=>年-月  3=>年
 * @return array
 */
function prDates1($map = [])
{

    $start = $map['start'];
    $end = $map['end'];
    $type = $map['type'];

    $time = [];
    //判断时间类型  年/月/日
    switch ($type)
    {
        case 1:
            $dt_start = strtotime($start);
            $dt_end = strtotime($end);
            //日
            while ($dt_start <= $dt_end)
            {
                $time[] = date('Y-m-d', $dt_start);
                $dt_start = strtotime('+1 day', $dt_start);
            }
            break;
        case 2:
            $dt_start = strtotime($start);
            $dt_end = strtotime($end);
            //月
            while ($dt_start <= $dt_end)
            {
                $time[] = date('Y-m', $dt_start);
                $dt_start = strtotime('+1 month', $dt_start);
            }
            break;
        case 3:
            $dt_start = strtotime($start . '-1');
            $dt_end = strtotime($end . '-1');
            //年
            while ($dt_start <= $dt_end)
            {
                $time[] = date('Y', $dt_start);
                $dt_start = strtotime('+1 year', $dt_start);
            }
            break;
    }
    return $time;
}

/**
 * 将运势加入运算队列,一笔订单所有数据统一加入队列
 * @param array $map
 *  oid int 订单id
 *  recode_info array[object,object] 档案信息
 *  unlock_time string 解锁时间 如：2019-6
 *  ostatus int 订单状态
 *  ftype int 2=>月运 3=>年运
 *  is_last int 0=> 1=>当前队列为解锁队列中的最后一个（最后一个计算完成需要发送通知）
 * @throws \app\common\lib\exception\ApiException
 */
function fortune_redis_job($map = [])
{
    $oid = $map['oid'];
    $order_id = $map['order_id'];
    $recode_info = $map['recode_info'];
    $unlock_time = $map['unlock_time'];
    $o_status = $map['ostatus'];
    $ftype = $map['ftype'];
    $is_last = isset($map['is_last']) ? $map['is_last'] : 1;

    switch ($ftype)
    {
        case 2:
            $fname = 'month';
            break;
        case 3:
            $fname = 'year';
            break;
        default :
            $fname = '';
            break;
    }
    if ($fname != '')
    {
        // 运势队列消费时需要的数据
        $jobData = [
            'oid' => $oid,
            'order_id' => $order_id,
            'recode' => $recode_info,
            'start_time' => $unlock_time,
            'type' => $fname,
            'status' => $o_status,
            'is_last' => $is_last
        ];

        $queueConfig = config('queue');

        if (Util::getVips($recode_info[0]['uid'], $ftype, 0))
        {
            $queueConfig['fortune_delay'] = 0;
        }
        queuePush($queueConfig['fortune_task'], $jobData, $queueConfig['fortune_queue'], $queueConfig['fortune_delay']);
    }

    return;
}

/**
 * 将数组转成url字符串
 * @param $paraMap
 * @param $urlencode
 * @return bool|string
 */
function formatBizQueryParaMap($paraMap, $urlencode)
{
    $buff = "";
    ksort($paraMap);
    foreach ($paraMap as $k => $v)
    {
        if ($urlencode)
        {
            $v = urlencode($v);
        }
        $buff .= ($k) . "=" . $v . "&";
    }
    $reqPar = '';
    if (strlen($buff) > 0)
    {
        $reqPar = substr($buff, 0, strlen($buff) - 1);
    }
    return $reqPar;
}

/**
 * 将url请求参数的字符串转为数组
 * @param $query
 * @return array
 */
function convertUrlQuery($query)
{
    $queryParts = explode('&', $query);
    $params = [];
    foreach ($queryParts as $param)
    {
        $item = explode('=', $param);
        $params[$item[0]] = $item[1];
    }
    return $params;
}

/**
 * 封闭curl的调用接口
 * $url(网址），$ifpost(用post传值是需调为1)，$datafields(post的数据)
 * @param $url
 * @param int $ifpost
 * @param string $datafields
 * @param string $cookiefile
 * @param bool $v
 * @return bool|string
 */
function curl($url, $ifpost = 0, $datafields = '', $cookiefile = '', $v = false)
{
    $header = ["Connection: Keep-Alive", "Accept: text/html, application/xhtml+xml, */*", "Pragma: no-cache", "Accept-Language: zh-Hans-CN,zh-Hans;q=0.8,en-US;q=0.5,en;q=0.3", "User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)"];
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, $v);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    $ifpost && curl_setopt($ch, CURLOPT_POST, $ifpost);
    $ifpost && curl_setopt($ch, CURLOPT_POSTFIELDS, $datafields);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
    $cookiefile && curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
    $cookiefile && curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    $r = curl_exec($ch);
    curl_close($ch);
    return $r;
}

/**
 * 获取不同商品的活动折扣  2019-05-31 00:00:00 1559232000
 * @param int $gid 商品id
 * @param string $start_time 解锁运势的时间 格式 Y-m
 * @return array
 */
function active($gid = 0, $start_time = '2019-05')
{
    $arr = [
        'discount' => 0,
        'indexGift' => false//首页大礼包开关
    ];
//    /**
//     * 活动已结束，直接返回默认数据 2019-07-17
//     */
//    return $arr;

    $now_time = time();
    /**
     * 双十一活动
     * 全部商品 在2019年11月8日00:00:00 ~11月15日23:59:59 购买八折
     *  2019-11-8 00:00:00   1573142400
     *  2019-11-15 00:00:00   1573833600
     */
    if (1573142400 <= $now_time && $now_time < 1573833600 && in_array($gid, config('goods.all_id')))
    {
        $arr['discount'] = 0.8;
    }


    /**
     *  助你度水逆
     *  月运，在2019年10月28日00:00到2019年11月1日23:59:59，八八折优惠
     *  2019-10-28 00:00:00   1572192000
     *  2019-11-01 23:59:59   1572623999
     */
//    if (1572192000 <= $now_time && $now_time < 1572623999 && in_array($gid, config('goods.month_id')))
//    {
//        $arr['discount'] = 0.88;
//    }

    /**
     *  开学季
     *  日运月运年运，与所有占星课程，在2019年9月3日00:00到2019年9月11日00:00:00，九折优惠
     *  2019-09-03 00:00:00   1567440000
     *  2019-09-11 00:00:00   1568131200
     */
//    $gids = array_merge(config('goods.fortune_id'), config('goods.video_id'));
//    if (1567440000 <= $now_time && $now_time < 1568131199 && in_array($gid, $gids))
//    {
//        $arr['discount'] = 0.9;
//    }
    /**
     * 中秋活动  日运，月运，年运打九折
     * 2019-09-12 00:00:00   1568217600
     * 2019-09-15 23:59:59:59   1568563199
     */
//    if (1568217600 <= $now_time && $now_time < 1568563199 && in_array($gid, config('goods.fortune_id')))
//    {
//        $arr['discount'] = 0.9;
//    }

    /**
     * ②若是6.2到6.15(包含6.15)月度运势打九折(暑假)
     * 2019-06-02 00:00:00  1559404800
     * 2019-06-15 23:59:59  1560614399
     */
//    if (1559404800 <= $now_time && $now_time <= 1560614399 && in_array($gid, config('goods.month_id')))
//    {
//        $arr['discount'] = 0.9;
//
//    }
    /**
     * ②若是6.2到6.15(包含6.15)月度运势打九折(暑假)
     * 2019-06-02 00:00:00  1559404800
     * 2019-06-15 23:59:59  1560614399
     */
//    if (1559404800 <= $now_time && $now_time <= 1560614399 && in_array($gid, config('goods.month_id')))
//    {
//        $arr['discount'] = 0.9;
//    }
    /**
     * ②若是6.17到6.19(包含6.19)全部商品打八折(京东6.18)
     * 2019-06-17 00:00:00  1560700800
     * 2019-06-20 00:00:00  1560960000
     */
//    if (1560700800 <= $now_time && $now_time <= 1560960000)
//    {
//        $arr['discount'] = 0.8;
//    }
    /**
     * 六一活动
     * ①若是六月一日当天且够买的六月运势打七折
     * 2019-06-01 00:00:00   1559318400
     * 2019-06-01 23:59:59   1559404799
     */
//    if (1559318400 <= $now_time && $now_time <= 1559404799 && $gid == 20 && $start_time == '2019-06')
//    {
//        $arr['discount'] = 0.7;
//    }
    /**
     * ③6.(7,8,9) 当天购买幸运之城打九折(暑假)
     * 2019-06-07 00:00:00  1559836800
     * 2019-06-09 23:59:59  1560095999
     */
//    if (1559836800 <= $now_time && $now_time <= 1560095999 && in_array($gid, config('goods.acg_id')))
//    {
//        $arr['discount'] = 0.9;
//    }
    return $arr;
}

/**
 * 递归获取无限级分类
 * @param array $data
 * @param int $id 母id
 * @return array
 */
function getChild($data = [], $id = 0)
{
    //创建一个保存最后输出结果的数据
    $tree = [];
    //循环所有数据找到pid为传入id的数组，也就是找到id的儿子们
    foreach ($data as $key => $value)
    {
        //找到了儿子
        if ($value['pid'] == $id)
        {
            //将数组保存进最后结果
            $tree[$value['id']] = $value;
            //为了减少数据量删掉了自己，因为自己不可能是自己的儿子。。
            unset($data[$key]);
            //将儿子的儿孙数组保存到儿子的child数组里（递归查找）
            $tree[$value['id']]['child'] = getChild($data, $value['id']);
        }
    }
    return $tree;
}

/**
 * 数组key和value保持一致
 * @param $data
 * @return array
 */
function array_flip_key_value($data)
{
    $array = [];
    foreach ($data as $id)
    {
        $array[$id] = $id;
    }
    return $array;
}

/**
 * 截取特定字符前面和后面的内容
 * @param string $str
 * @param string $needle
 * @return mixed
 */
function substring(string $str, string $needle)
{
    $data['before'] = substr($str, 0, strrpos($str, $needle));
    if (strrpos($str, $needle) === false)
    {
        $data['after'] = substr($str, strrpos($str, $needle));
    } else
    {
        $data['after'] = substr($str, strrpos($str, $needle) + 1);
    }
    return $data;
}

/**
 * 数组key赋值为value
 * @param array $data 一维数组
 * @return array|bool
 */
function keyValue(array $data)
{
    $ids = [];
    foreach ($data as $id)
    {
        if (is_array($id))
        {
            return false;
        }
        $ids[$id] = $id;
    }
    return $ids;
}

/**
 * 日期处理，默认转为时间戳
 * @param string $date 年-月-日 时:分:秒
 * @param string $expire_time
 * @param string $format 格式 Y-m-d / U
 * @param string $timezone 时区
 * @return int
 * @demo strtotimeModify('2020-06-10', '13:48:54','+1 month','Y-m-d');
 * @throws Exception
 */
function strtotimeModify($format = 'U', string $date = '', string $expire_time = '', $timezone = 'PRC')
{
    if (count(explode('-', $date)) == 1)
    {
        $date .= '-1';
    }
    $datetime = new \DateTime($date, new DateTimeZone($timezone));
    $datetime->setTimezone(new DateTimeZone($timezone));
    if ($expire_time)
    {
        $datetime->modify($expire_time);
    }
    return $datetime->format($format);
}

/**
 * 时间戳处理，默认转为日期
 * @param string $format 格式 Y-m-d / U
 * @param int $timestamp 时间戳
 * @param string $expire_time
 * @param string $timezone 时区
 * @return string
 * @demo dateModify('Y-m-d', 1591768134,'+1month');
 */
function dateModify(string $format = 'Y-m-d', $timestamp = 0, $expire_time = '', $timezone = 'PRC')
{
    $datetime = new \DateTime();
    $datetime->setTimezone(new DateTimeZone($timezone));
    $datetime->setTimestamp($timestamp);
    if ($expire_time)
    {
        $datetime->modify($expire_time);
    }
    return $datetime->format($format);
}


/**
 * 获取对应时区的时间
 * @param string $dateformat 时间格式
 * @param int $timestamp 时间戳
 * @param float $startTimezone 当前时间时区
 * @param float $endTimezone 需要转换成的时区时间
 * @param bool $isFormat 时间是否格式化
 * @return string
 * @throws Exception
 */
function gmdateModify($dateformat = 'Y-m-d H:i:s', $timestamp = 0, $startTimezone = 8.0, $endTimezone = 8.0, $isFormat = true)
{
    if (empty($timestamp))
    {
        $timestamp = time();
    }
    $timestamp = $timestamp + (8 - (float)$startTimezone) * 3600; // 先转换成东八区时间戳

    $result = gmdate($dateformat, $timestamp + (float)$endTimezone * 3600);
    if (!$isFormat)
    {
        $result = strtotimeModify('U', $result);
    }
    return $result;
}

/**
 * 转换成 年 天 时 分 秒
 * @param [type] $time
 * @return void
 */
function Sec2Time($time)
{
    if (is_numeric($time))
    {
        $value = [
            "years" => 0, "days" => 0, "hours" => 0,
            "minutes" => 0, "seconds" => 0,
        ];
        $t = '';
        if ($time >= 31556926)
        {
            $value["years"] = floor($time / 31556926);
            $time = ($time % 31556926);
            $t .= $value["years"] . "年";
        }
        if ($time >= 86400)
        {
            $value["days"] = floor($time / 86400);
            $time = ($time % 86400);
            $t .= $value["days"] . "天";
        }
        if ($time >= 3600)
        {
            $value["hours"] = floor($time / 3600);
            $time = ($time % 3600);
            $t .= $value["hours"] . "小时";
        }
        if ($time >= 60)
        {
            $value["minutes"] = floor($time / 60);
            $time = ($time % 60);
            $t .= $value["minutes"] . "分";
        }
        $value["seconds"] = floor($time);
        //return (array) $value;
        $t .= $value["seconds"] . "秒";
        return $t;

    } else
    {
        return (bool)false;
    }
}

/**
 * 转换成 年 天 时 分
 * @param [type] $time
 */
function Sec2Time1($time)
{
    if (is_numeric($time))
    {
        if ($time < 60)
        {
            return '刚刚';
        }

        return floor($time / 60) . "分钟前";
    } else
    {
        return (bool)false;
    }
}

/**
 * 转换 时 分
 * @param [type] $time
 * @return void
 */
function Sec2Time2($time)
{
    if (is_numeric($time))
    {
        $value = [
            "hours" => 0,
            "minutes" => 0,
        ];
        $t = '';

        if ($time >= 3600)
        {
            $value["hours"] = floor($time / 3600);
            $time = ($time % 3600);
            $t .= $value["hours"] . "小时";
        }
        if ($time >= 60)
        {
            $value["minutes"] = ceil($time / 60);
            $value["minutes"] = $value["minutes"] >= 59 ? 59 : $value["minutes"];
            $t .= $value["minutes"] . "分";
        }

        return $t;

    } else
    {
        return (bool)false;
    }
}

/**
 * 数组 值 转int
 * @param $arr
 * @param array $field
 * @return mixed
 */
function arrayKeyData2int($arr, $field = [])
{
    foreach ($field as $arrKey)
    {
        if (isset($arr[$arrKey]))
        {
            $arr[$arrKey] = (int)$arr[$arrKey];
        }
    }

    return $arr;
}

/**
 * 数组 值 转int
 * @param array $array
 * @return array
 */
function arrayInt(array $array): array
{
    return array_map(static function ($v)
    {
        if (is_array($v))
        {
            return arrayInt($v);
        }
        if (is_numeric($v))
        {
            if (filter_var($v, FILTER_VALIDATE_INT))
            {
                return (int)$v;
            }
            return (float)$v;
        }
        return $v;
    }, $array);
}

/**
 * 数组 取随机数量
 * @param array $array
 * @param int $num
 * @param int $type 1=>函数返回数组中的随机键名 2=>函数返回数组中的随机键值
 * @return array
 */
function arrayRandNum(array $array, int $num = 1, int $type = 1): array
{
    $randKey = array_rand($array, $num);
    if ($type === 1)
    {
        return $randKey;
    } else
    {
        if ($num === 1)
        {
            return [$array[$randKey]];
        }
        $resData = [];
        foreach ($randKey as $key)
        {
            $resData[] = $array[$key];
        }

        return $resData;
    }
}

/**
 * 生成uuid
 * @return string
 */
function uuid($uid)
{
    $chars = md5($uid);
    $uuidInfo = substr($chars, 0, 8) . '-'
        . substr($chars, 8, 4) . '-'
        . substr($chars, 12, 4) . '-'
        . substr($chars, 16, 4) . '-'
        . substr($chars, 20, 12);
    return strtoupper($uuidInfo);
}

/**
 * 将日期格式00000000转为0000-00-00
 * @param $date
 * @return string
 */
function convertDateFormatToStr($date)
{
    // 使用 substr 函数分割日期
    $year = substr($date, 0, 4);
    $month = substr($date, 4, 2);
    $day = substr($date, 6, 2);

    // 将各个部分组合成新的日期格式
    return $year . '-' . $month . '-' . $day;
}

/**
 * 将日期格式0000-00-00转为00000000
 * @param $date
 * @return array|string|string[]
 */
function convertDateFormatToInt($date)
{
    // 使用 str_replace 替换短横线
    return str_replace('-', '', $date);
}
